package com.autumn.aitraffic.controller;

import com.autumn.aitraffic.api.Result;
import com.autumn.aitraffic.domain.po.User;
import com.autumn.aitraffic.domain.vo.FaceAnalyzeVo;
import com.autumn.aitraffic.service.SmsService;
import com.autumn.aitraffic.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/login")
@CrossOrigin(origins = "*")
public class LoginController {

    @Autowired
    private UserService userService;
    @Autowired
    private SmsService smsService;
    @PostMapping()
    public Result login(@RequestBody User user){
        return userService.login(user.getUsername(), user.getPassword());
    }
    @GetMapping("/reg/phonesms")
    public Result check(@RequestParam(value = "phoneNumber") String telephone){
        return Result.succ("",smsService.sendSMSCode(telephone));
    }
    @PutMapping("/reg")
    public Result register(@RequestBody User user)
    {
        return userService.regist(user.getUsername(), user.getPassword(), user.getTelephone());
    }
    @PostMapping("faceReg")
    public Result faceReg(@RequestBody FaceAnalyzeVo faceAnalyzeVo){
        return  userService.faceReg(faceAnalyzeVo);
    }
    @PostMapping("face")
    public Result face(@RequestBody FaceAnalyzeVo faceAnalyzeVo){
        return userService.faceAnalyze(faceAnalyzeVo);
    }
}
